package com.tnovoselec.server.news;

import java.io.File;
import java.util.Date;
import java.util.Timer;

import org.apache.catalina.startup.Tomcat;

import com.tnovoselec.server.news.worker.RefreshNews;

public class Main {

	private static Timer timer;

	public static void main(String[] args) throws Exception {

		String webappDirLocation = "/usr/local/NewsServer/server/war/";
		// String webappDirLocation = "war/";
		Tomcat tomcat = new Tomcat();

		String webPort = System.getenv("PORT");
		if (webPort == null || webPort.isEmpty()) {
			webPort = "8085";
		}

		tomcat.setPort(Integer.valueOf(webPort));

		tomcat.addWebapp("", webappDirLocation);
		//tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());

		timer = new Timer();
		timer.schedule(new RefreshNews(), new Date(), 10 * 60 * 1000);

		tomcat.start();
		tomcat.getServer().await();

	}
}
